package com.dc.controller;

import com.dc.base.baseController.BaseController;
import com.dc.base.em.ErrorMessageEnum;
import com.dc.base.vo.BaseModel;
import com.dc.base.vo.BusinessException;
import com.dc.model.User;
import com.dc.service.LoginLogService;
import com.wordnik.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/loginLog")
public class LoginLogController extends BaseController {
    @Autowired
    LoginLogService loginLogService;

    @ApiOperation(value="分页查询登录日志",httpMethod = "GET",notes="查询")
    @RequestMapping(value="/selectPageLoginLog", method = RequestMethod.GET)
    @ResponseBody
    public BaseModel selectPageLoginLog(@RequestParam(value="curr_page",defaultValue = "1") Integer curr_page,
                                        @RequestParam(value="page_size",defaultValue = "10") Integer page_size,
                                        BaseModel baseModel,
                                        @RequestParam(value="user_account",required = false) String user_account,
                                        @RequestParam(value="user_name",required = false) String user_name,
                                        HttpServletRequest request)throws Exception{

        HttpSession session =request.getSession();
        User currentUser=(User)session.getAttribute("currentUser");
        if(currentUser ==null){
            throw new BusinessException(ErrorMessageEnum.LOGIN_TIMEOUT);
        }
        return loginLogService.selectPageLoginLog(curr_page,page_size,baseModel,user_name,user_account);

    }

}
